/*Version 1.0*/
#include <stdlib.h>
#include "Menu.h"

void CreerMenu()
{
  GtkWidget *pWindow;
  GtkWidget *pVBox;
  GtkWidget *pMenuBar;
  GtkWidget *pMenu;
  GtkWidget *pMenuItem;

  /* Cr?ation de la fen?tre */
  pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(pWindow), "GtkMenu");
  gtk_window_set_default_size(GTK_WINDOW(pWindow), 320, 100);
  g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);

  /* Cr?ation de la GtkVBox */
  pVBox = gtk_box_new(TRUE, 0);
  gtk_container_add(GTK_CONTAINER(pWindow), pVBox);

  /**** Creation du menu ****/
  pMenuBar = gtk_menu_bar_new();
  
  pMenu = gtk_menu_new();
  
  pMenuItem = gtk_menu_item_new_with_label("Nouveau");
  g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnNouveau), (GtkWidget*) pWindow);
  gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

  pMenuItem = gtk_menu_item_new_with_label("Ouvrir");
  g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnOuvrir), (GtkWidget*) pWindow);
  gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

  pMenuItem = gtk_menu_item_new_with_label("Enregistrer");
  g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnSauver), (GtkWidget*) pWindow);
  gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

  pMenuItem = gtk_menu_item_new_with_label("Fermer");
  g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnQuitter), (GtkWidget*) pWindow);
  gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);

  pMenuItem = gtk_menu_item_new_with_label("Fichier");

  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);

  gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);

  /* Ajout du menu a la fenetre */
  gtk_box_pack_start(GTK_BOX(pVBox), pMenuBar, FALSE, FALSE, 0);
  gtk_widget_show_all(pWindow);

}

void OnQuitter(GtkWidget* widget, gpointer data)
{
  GtkWidget *pQuestion;
  pQuestion = gtk_message_dialog_new(GTK_WINDOW(data),
				     GTK_DIALOG_MODAL,
				     GTK_MESSAGE_QUESTION,
				     GTK_BUTTONS_YES_NO,
				     "Voulez vous vraiment\n"
				     "quitter le programme?");

  switch(gtk_dialog_run(GTK_DIALOG(pQuestion)))
  {
      case GTK_RESPONSE_YES:gtk_main_quit();
      break;

      case GTK_RESPONSE_NONE:

      case GTK_RESPONSE_NO:gtk_widget_destroy(pQuestion);
      break;
  }
}
void OnOuvrir(GtkWidget* widget, gpointer data)
{
}
void OnSauver(GtkWidget* widget, gpointer data)
{
}
void OnNouveau(GtkWidget* widget, gpointer data)
{
}
